//! URL工具
//! 
//! 提供URL解析和处理功能

use url::Url;

/// 解析URL
pub fn parse_url(url_str: &str) -> Result<Url, url::ParseError> {
    Url::parse(url_str)
}

/// 获取URL的域名
pub fn get_domain(url_str: &str) -> Result<String, Box<dyn std::error::Error>> {
    let url = Url::parse(url_str)?;
    Ok(url.host_str().unwrap_or("").to_string())
}

/// URL编码
pub fn url_encode(input: &str) -> String {
    urlencoding::encode(input).to_string()
}

/// URL解码
pub fn url_decode(input: &str) -> Result<String, Box<dyn std::error::Error>> {
    Ok(urlencoding::decode(input)?.to_string())
}